package com.yonyou.pmclouds.repeatwork.process;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.DateUtils;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.repeatwork.entity.RepeatWorkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 计算复工单对应项目累计停工时间
 */
@Component
public class CaculateStopDaysProcessor implements SingleProcessor<RepeatWorkVO> {
    @Autowired
    private ProjectSimpleQuery projectSimpleQuery;

    @Override
    public void process(RepeatWorkVO vo, RepeatWorkVO orig) throws BusinessException {
        //查询项目档案上次的累计停工天数。
        String pk_project = vo.getPkProject();
        ProjectVO projectVO = projectSimpleQuery.queryProject(pk_project);
        Integer totworkStopDays = projectVO.getTotworkstopDays();
        //查询和当前复工单对应的停工单，然后计算本次停工天数。
        Date repeatDate = vo.getRepeatDate();
        long currworkStopDays = DateUtils.getDaysBetween(projectVO.getWorkstopDate(),repeatDate);
        vo.setTotalstopdays((int) (currworkStopDays+totworkStopDays));
        //维护复工前上次的停工天数，后续回退需要
        vo.setLasttotalstopdays(totworkStopDays);
    }

}
